package models

import (
	"github.com/beego/beego/v2/client/orm"
	_ "github.com/go-sql-driver/mysql"
)

type UserToken struct {
	Token      string `orm:"pk;column(token);size(50)" description:"用户名" json:"token"`
	UserId     int64  `orm:"column(user_id);size(10)" description:"昵称" json:"user_id"`
	Createtime int64  `orm:"column(createtime);size(10)" description:"密码" json:"createtime"`
	Expiretime int64  `orm:"column(expiretime);size(10)" description:"密码" json:"expiretime"`
}

func (*UserToken) TableName() string {
	return "fa_user_token"
}

//在init中注册定义的model
func init() {
	orm.RegisterModel(new(UserToken))
}

func (ut *UserToken) GetByToken(token string) *UserToken {
	o := orm.NewOrm()
	if err := o.QueryTable(ut.TableName()).Filter("token", token).One(ut); err != nil {
		return nil
	}
	return ut
}
